<?php
/*
 * 进云智能生成平台
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
 */
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
if($_RQ['op']=='main'){
	//获取站点模板下面的代码
	$pageid=intval($_RQ['pageid']);
	if($_RQ['id'] && !$pageid){
		$id=intval($_RQ['id']);
		$tpls=pdo_get('core_account_web_tpl',array('web_id'=>$id,'uniacid'=>$_SESSION['uniacid']),array('id','tpl_id','html','updatetime','setting'),'is_open desc');
		$pageid=$tpls['id'];
	}
	$tpls=pdo_get('core_account_web_tpl',array('id'=>$pageid,'uniacid'=>$_SESSION['uniacid']),array('id','tpl_id','items','setting','web_id'));
	if(!$tpls['items']){
		exi('指定的页面，没有设计内容！','error');
	}
	$setting=json_decode($tpls['setting'],true);
	if($_SESSION['appgid'] && $_SESSION['fromh5wxapp']!=1){
		$item=pdo_get('core_account_wxapp',array('id'=>$_SESSION['appgid'],'uniacid'=>$_SESSION['uniacid']),array('id','setting','title'));
		$item['setting'] =$item['setting'] ? json_decode($item['setting'],true):array('isfooter'=>0);
		if($item['setting']['isfooter']){
			$setting['isfooter']=1;
			$footer=$item['setting']['footer'];
		}else{
			$footer=$setting['isfooter']==1?$setting['footer']:array();
		}
	}else{
		$item=pdo_get('core_mobile_web',array('id'=>$tpls['web_id'],'uniacid'=>$_SESSION['uniacid']),array('menu_id','syscolor'));
		if($item['menu_id']){
			$setting['isfooter']=1;
			$footer=pdo_getcolumn('core_diy_menu',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['menu_id']),'data');
			$footer=json_decode($footer,true);
		}else{
			$footer=$setting['isfooter']==1?$setting['footer']:array();
		}
	}
	if($item['merchid']){
		$return['myshop']['id']=$item['merchid'];
	}
	$tpls['items']=json_decode($tpls['items'],true);
	foreach($tpls['items'] as $k=>&$iv){
		$iv['params']['nid']=$iv['nid'];
		$iv=$iv['params'];
		if($iv['get_data']){
			foreach($iv as $ik=>$irow){
				if(is_string($irow) && $ik!='i' && $ik!='core' && $ik!='p' && $ik!='plugin' && $ik!='a' && $ik!='action' && $ik!='from' && $ik!='get_data' && $ik!='params'){
					$iv['get_data']['query'] .='&'.$ik.'='.$irow;
				}	
			}
			$iv['get_data']['url']=sys_shorturl($iv['get_data']);
		}else{
			$iv['get_data']=array();
		}
	}
	$setting['footer']=$footer;
	if($tpls['tpl_id']){
		$tpls['title']=$setting['top']['title']?:$tpls['title'];
		$item['title']=$tpls['title']?:$item['title'];
	}else{
		$item['title']=$setting['top']['title']?:$item['title'];
	}
	if($setting['level']['shoplevels']){
		if(cfc('core')->plugin_exists('jy_weishop')){
			$levelinfo = model('jy_weishop/member')->get_level();
			if(strpos($setting['level']['shoplevels'],';'.$levelinfo['id'].';')===false){
				exi('您没有权限浏览该页面！','error',$setting['level']['shoplink']);
			}
		}
	}
	$tpls['setting']=$setting;
	$return['tpls']=$tpls;
	$return['item']=$item;
	$return['sharedata']=array(
		'title'=>$item['title'],
		'desc'=>$item['description']?:$item['title'].'的描述',
		'link'=>custom_url('core/welcome//id='.$id.'&fromuser='.$_SESSION['uid'],true),
		'imgUrl'=>tomedia($item['picurl'])
	);
	exi($return);
}